|
|
|
|
|
|
|
(table continued from previous page) |
|
|
|
|
| Control | Property | Setting | | DatabaseName | C:\TYSDBVB5\SOURCE\DATA\ERRORS\
ERRORDB.MDB | | Height | 360 | | RecordSource | "Table1" | | Top | 975 | | Width | 4665 | | VB.Label | Name | lblName | | Caption | "Name" | | Height | 255 | | Left | 120 | | Top | 540 | | Width | 1215 | | VB.Label | Name | lblKeyField | | Caption | "Key Field" | | Height | 255 | | Left | 120 | | Top | 120 | | Width | 1215 |
|
|
|
|
|
|
The only code you need to add to this form is a single line to support the Add button. Place the following code behind the cmdAdd_Click event. |
|
|
|
|
|
|
|
|
Private Sub cmdAdd_Click()
Data1.Recordset.AddNew
End Sub |
|
|
|
|
|
|
|
|
Now save the new form as DATAERR.FRM and the project as DATAERR.VBP. When you run the project, you can test the built-in error trapping for Microsoft data controls by adding a new, duplicate record to the table. Press the Add button, then enter KF109 in the KeyField input box and press one of the arrows on the data control to force it to save the record. You should see a database error message that looks like the one in Figure 14.12. |
|
|
|
|
|
|
|
|
Are you surprised? You didn't add an error trap to the data entry form, but you still got a complete database error message! The Visual Basic data control is kind enough to provide complete database error reporting even if you have no error handlers in your Visual Basic program. Along with the automatic errors, the data control also has the Error event. Each time a data-related error occurs, this event occurs. You can add code in the Data1_Error event to automatically fix errors, display better error messages, and so on. |
|
|
|
|
|